<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">外部用户计算任务</ui:define>
    <ui:define name="content">
        <h:form>
            <div class="topbar clearfix"
                 style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar id="buttonToolBar">
                    <f:facet name="right">
                        <p:button value="返回" icon="fa fa-reply-all" href="#{currentUserBean.back}"></p:button>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">
                <p:tabView scrollable="true" style="padding-top: 20px;background: #edf0f5;"
                           activeIndex="#{externalSmsConditionViewBean.activeIndex}">
                    <p:ajax event="tabChange" update="@form"/>
                    <p:tab title="计算任务"
                           rendered="#{externalSmsConditionViewBean.smsCalculateTask != null and externalSmsConditionViewBean.calculateCondition != null}">
                        <div class="ui-g">
                            <div class="ui-g-12">
                                <div class="card ui-g-12">
                                    <div class="ui-g-1">
                                        <p:outputLabel value="任务名称"/>
                                    </div>
                                    <div class="ui-g-11">
                                        <p:inputText value="#{externalSmsConditionViewBean.calculateCondition.name}"
                                                     disabled="#{!externalSmsConditionViewBean.canEditCalculateTask()}"/>
                                    </div>
                                </div>
                            </div>

                            <div class="ui-g-12">
                                <div class="card ui-g-12">

                                    <div class="ui-g-1">
                                        <p:outputLabel value="选择通道"/>
                                        <strong style="color: red">*</strong>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:selectOneMenu
                                                value="#{externalSmsConditionViewBean.calculateCondition.externalChannel}" filter="true"
                                                filterMatchMode="contains">
                                            <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                                          noSelectionOption="true"/>
                                            <f:selectItems
                                                    value="#{externalSmsConditionViewBean.dictionaries[DictionaryCode.SMS_EXTERNAL_CHANNEL]}"
                                                    var="dic"
                                                    itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                        </p:selectOneMenu>
                                    </div>

                                    <div class="ui-g-1">
                                        <p:outputLabel value="获取同盾分时间"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:calendar value="#{externalSmsConditionViewBean.calculateCondition.tongDunStartTime}"
                                                    styleClass="autoWidthCalendar"
                                                    locale="#{constants:get('LOCALE')}"
                                                    timeZone="#{constants:get('TIME_ZONE')}"
                                                    pattern="#{constants:get('DATE_FORMAT')}"
                                                    navigator="true"
                                                    converterMessage="日期格式输入错误! 例子: 2018-04-23"/>
                                        <span>—</span>
                                        <p:calendar value="#{externalSmsConditionViewBean.calculateCondition.tongDunEndTime}"
                                                    styleClass="autoWidthCalendar"
                                                    locale="#{constants:get('LOCALE')}"
                                                    timeZone="#{constants:get('TIME_ZONE')}"
                                                    pattern="#{constants:get('DATE_FORMAT')}"
                                                    navigator="true"
                                                    converterMessage="日期格式输入错误! 例子: 2018-04-23"/>
                                    </div>

                                    <div class="ui-g-1">
                                        <p:outputLabel value="同盾分"/>
                                        <strong style="color: red">*</strong>
                                    </div>
                                    <div class="ui-g-2">
                                        <p:inputNumber id="tongDunMinScore" minValue="0" value="#{externalSmsConditionViewBean.calculateCondition.tongDunMinScore}"/>
                                    </div>
                                    <div class="ui-g-2">
                                        <p:inputNumber id="tongDunMaxScore" maxValue="100" value="#{externalSmsConditionViewBean.calculateCondition.tongDunMaxScore}"/>
                                    </div>

                                </div>
                            </div>


                            <div class="ui-g-12">
                                <div class="card ui-g-12">
                                    <div class="ui-g-1">
                                        运营商
                                    </div>
                                    <div class="ui-g-5">
                                        <p:selectCheckboxMenu label="-请选择-"  value="#{externalSmsConditionViewBean.calculateCondition.telecomOperators}"
                                                              disabled="#{!externalSmsConditionViewBean.canEditCalculateTask()}"
                                                              updateLabel="true" multiple="true" filter="true">
                                            <f:selectItem itemLabel="移动" itemValue="移动"/>
                                            <f:selectItem itemLabel="联通" itemValue="联通"/>
                                            <f:selectItem itemLabel="电信" itemValue="电信"/>
                                        </p:selectCheckboxMenu>
                                    </div>

                                    <div class="ui-g-1">
                                        <p:outputLabel value="用户类型"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:selectCheckboxMenu label="-请选择-" value="#{externalSmsConditionViewBean.calculateCondition.userTypes}"
                                                              disabled="#{!externalSmsConditionViewBean.canEditCalculateTask()}"
                                                              updateLabel="true" multiple="true" filter="true">
                                            <f:selectItem itemLabel="注册用户" itemValue="0"/>
                                            <f:selectItem itemLabel="登记未注册用户" itemValue="1"/>
                                        </p:selectCheckboxMenu>
                                    </div>

                                    <div class="ui-g-1">
                                        <p:outputLabel value="地区"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:selectCheckboxMenu label="-请选择-" id="province" value="#{externalSmsConditionViewBean.calculateCondition.provinces}"
                                                              disabled="#{!externalSmsConditionViewBean.canEditCalculateTask()}"
                                                              updateLabel="true" multiple="true" filter="true">
                                            <f:selectItems value="#{externalSmsConditionViewBean.provinces}" />
                                        </p:selectCheckboxMenu>
                                    </div>
                                </div>
                                
                            </div>
                        </div>
                    </p:tab>

                    <p:tab title="发送任务"
                           rendered="#{externalSmsConditionViewBean.smsSendTask != null}">
                        <div class="ui-g">
                            <div class="ui-g-12">
                                <div class="card ui-g-12">
                                    <div class="ui-g-1">
                                        <p:outputLabel value="短信平台"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:selectOneButton value="#{externalSmsConditionViewBean.smsSendTask.platformChannel}"
                                                           disabled="#{!externalSmsConditionViewBean.canEditSendTask()}">
                                            <f:selectItems
                                                    value="#{externalSmsConditionViewBean.dictionaries[DictionaryCode.SMS_PLATFORM_CHANNEL]}"
                                                    var="dic"
                                                    itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                        </p:selectOneButton>
                                    </div>

                                    <div class="ui-g-2">
                                        <p:outputLabel value="计划发送时间"/>
                                    </div>
                                    <div class="ui-g-4">
                                        <p:calendar value="#{externalSmsConditionViewBean.smsSendTask.executeTime}"
                                                    locale="#{constants:get('LOCALE')}"
                                                    timeZone="#{constants:get('TIME_ZONE')}"
                                                    pattern="#{constants:get('DATETIME_FORMAT')}"
                                                    readonlyInput="true"
                                                    disabled="#{!externalSmsConditionViewBean.canEditSendTask()}"/>
                                    </div>
                                </div>
                            </div>
                            <div class=" ui-g-12">
                                <div class="card ui-g-12">
                                    <div class="ui-g-12">
                                        <h3><b>短信内容</b></h3>
                                    </div>
                                    <div class="ui-g-1">
                                        <p:outputLabel value="模板类型"/>
                                    </div>
                                    <div class="ui-g-11">
                                        <p:selectOneButton value="#{externalSmsConditionViewBean.selectedTemplateGroup}"
                                                           disabled="#{!externalSmsConditionViewBean.canEditSendTask()}">
                                            <p:ajax event="change"
                                                    listener="#{externalSmsConditionViewBean.onSelectSmsTemplateGroup}"
                                                    update="smsTemplateSelect"/>
                                            <f:selectItem itemLabel="不限" itemValue=""/>
                                            <f:selectItems
                                                    value="#{externalSmsConditionViewBean.dictionaries[DictionaryCode.SMS_TEMPLATE_GROUP]}"
                                                    var="dic"
                                                    itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                        </p:selectOneButton>
                                    </div>
                                    <div class="ui-g-1">短信模板</div>
                                    <div class="ui-g-5">
                                        <p:selectOneMenu id="smsTemplateSelect" value="#{externalSmsConditionViewBean.template}"
                                                         filter="true"
                                                         filterMatchMode="contains"
                                                         disabled="#{!externalSmsConditionViewBean.canEditSendTask()}">
                                            <p:ajax event="change" listener="#{externalSmsConditionViewBean.onUpdateTemplate}"
                                                    update="content"/>
                                            <f:selectItem itemLabel="请选择" itemValue="" noSelectionOption="true"/>
                                            <f:selectItems
                                                    value="#{externalSmsConditionViewBean.smsTemplates}"
                                                    var="dic"
                                                    itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                        </p:selectOneMenu>
                                    </div>
                                    <div class="ui-g-1">
                                        <p:outputLabel value="活动名称"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:inputText value="#{externalSmsConditionViewBean.activityName}"
                                                     disabled="#{!externalSmsConditionViewBean.canEditSendTask()}">
                                            <p:ajax event="change" listener="#{externalSmsConditionViewBean.onUpdateTemplate}"
                                                    update="content"/>
                                        </p:inputText>
                                    </div>
                                    <div class="ui-g-6"/>
                                    <div class="ui-g-1">
                                        <p:outputLabel value="变量1"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:inputText value="#{externalSmsConditionViewBean.var1}"
                                                     disabled="#{!externalSmsConditionViewBean.canEditSendTask()}">
                                            <p:ajax event="change" listener="#{externalSmsConditionViewBean.onUpdateTemplate}"
                                                    update="content"/>
                                        </p:inputText>
                                    </div>
                                    <div class="ui-g-1">
                                        <p:outputLabel value="变量2"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:inputText value="#{externalSmsConditionViewBean.var2}"
                                                     disabled="#{!externalSmsConditionViewBean.canEditSendTask()}">
                                            <p:ajax event="change" listener="#{externalSmsConditionViewBean.onUpdateTemplate}"
                                                    update="content"/>
                                        </p:inputText>
                                    </div>
                                    <div class="ui-g-1">
                                        <p:outputLabel value="变量3"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:inputText value="#{externalSmsConditionViewBean.var3}"
                                                     disabled="#{!externalSmsConditionViewBean.canEditSendTask()}">
                                            <p:ajax event="change" listener="#{externalSmsConditionViewBean.onUpdateTemplate}"
                                                    update="content"/>
                                        </p:inputText>
                                    </div>
                                    <div class="ui-g-1">
                                        <p:outputLabel value="变量4"/>
                                    </div>
                                    <div class="ui-g-5">
                                        <p:inputText value="#{externalSmsConditionViewBean.var4}"
                                                     disabled="#{!externalSmsConditionViewBean.canEditSendTask()}">
                                            <p:ajax event="change" listener="#{externalSmsConditionViewBean.onUpdateTemplate}"
                                                    update="content"/>
                                        </p:inputText>
                                    </div>
                                    
                                    <div class="ui-g-1">
		                                <p:outputLabel value="甲方名称"/>
		                            </div>
		                            <div class="ui-g-5">
		                                <p:inputText value="#{externalSmsConditionViewBean.smsSendTask.firstPartyName}"
                                                     disabled="#{!externalSmsConditionViewBean.canEditSendTask()}">
		                                </p:inputText>
		                            </div>

                                    <div class="ui-g-12">
                                        <div class="ui-g-1">
                                            <p:outputLabel value="短信文案"/>
                                        </div>
                                        <div class="ui-g-11">
                                            <p:inputTextarea id="content"
                                                             value="#{externalSmsConditionViewBean.smsSendTask.content}"
                                                             rows="10"
                                                             counter="display" maxlength="70"
                                                             counterTemplate="剩余 {0} 字, 短信文案字数最大限制为70字"
                                                             disabled="#{!externalSmsConditionViewBean.canEditSendTask()}"/>
                                            <h:outputText id="display"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </p:tab>


                </p:tabView>
            </div>
        </h:form>
    </ui:define>
</ui:composition>